
#include "stack_base_array.h"
#include <stdio.h>
#include <stdlib.h>

/*创建栈*/
STACK *stack_create(int cap)
{
	STACK *stack = malloc(sizeof(STACK));
	stack->arr = malloc(cap * sizeof(int));
	stack->cap = cap;
	stack->top = 0;
    return stack;
}
/*销毁栈*/
void stack_destroy(STACK *stack)
{
	free(stack->arr);
    stack->arr = NULL;//防止野指针
	free(stack);
    stack = NULL; //防止野指针
}
/*压栈*/
void stack_push(STACK *stack, int data)
{
	stack->arr[stack->top] = data;
	stack->top++;
}
/*弹栈*/
int stack_pop(STACK *stack)
{
	return stack->arr[--(stack->top)];
}
/*判空 如果为空返回1， 否则返回0*/
int stack_empty(STACK *stack)
{
	return !stack->top;
}
/*判满,如果满返回1 ，否则返回0*/
int stack_full(STACK *stack)
{
	if(stack->top == stack->cap)
	{	
		return 1;
	}
	return 0;
}







